﻿CREATE PROCEDURE [dbo].[yaf_checkemail_update](
                @Hash NVARCHAR(32))
AS
    BEGIN
        DECLARE  @UserID INT
        DECLARE  @CheckEmailID INT
        DECLARE  @Email NVARCHAR(50)
        SET @UserID = NULL
        SELECT @CheckEmailID = CheckEmailID , @UserID = UserID , @Email = Email FROM yaf_CheckEmail WHERE [Hash] = @Hash
        IF @UserID IS NULL
        BEGIN
            SELECT CONVERT(BIT,0)
            RETURN
        END
        -- Update new user email
        UPDATE yaf_User
        SET    Email = @Email,
               Flags = Flags | 2
        WHERE  UserID = @UserID
        DELETE yaf_CheckEmail
        WHERE  CheckEmailID = @CheckEmailID
        SELECT CONVERT(BIT,1)
    END


